package Controller;

import java.util.List;

import org.dom4j.xpp.ProxyXmlStartTag;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

import Model.Category;
import Model.Product;
import Model.HibernateUtils;
public class ControladorProducto {
	public void insertar( String nombre, String description, String proveedor, double cost, double iva, String cantidad, Category cat) {
		Session session = HibernateUtils.SESSION_FACTORY.openSession();
		session.beginTransaction();
		Product pr = new Product();
		pr.setNombre(nombre);
		pr.setDescription(description);
		pr.setCodS(proveedor);
		pr.setCategory(cat);
		pr.setCost(cost);
		pr.setIva(iva);
		pr.setAmount(cantidad);
		session.save(pr);
		session.getTransaction().commit();
		session.close();
	}

	public void Eliminar(Product product) {
		Session session = HibernateUtils.SESSION_FACTORY.openSession();
		session.beginTransaction();// beginning of the transaction
		session.delete(product);
		session.getTransaction().commit();// end of transaction
		session.close();// end of session

	}

	public List<Product> cargarTodos() {
		Session session = HibernateUtils.SESSION_FACTORY.openSession();
		List<Product> lst = session.createCriteria(Product.class).list();
		session.close();// end of session

		return lst;
	}

	public void Actualizar(Product product) {
		Session session = HibernateUtils.SESSION_FACTORY.openSession();
		session.beginTransaction();
		session.saveOrUpdate(product);
		session.getTransaction().commit();
		session.close();
	}
}

